﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.Globalization;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Caching;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace CallCenter.Web.Controllers
{
    public class EmployeeGridController : BaseController
    {
        // GET: EmployeeGrid
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult EmployeeHistory()
        {
            EmployeeGridVM cmpy = new EmployeeGridVM();
            return View(cmpy);
        }
        [HttpGet]
        public JsonResult GetEmployees()
        {
            var scratchPads = this.Bridge.EmployeeUtility.GetEmp();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

   

        public JsonResult GetDepartment()
        {
            var scratchPads = this.Bridge.ProductRequestUtility.GetAllProductRequests(30);

            return Json(scratchPads, JsonRequestBehavior.AllowGet);

        }
        [HttpPost]
        public JsonResult CreateEmployee(EmployeeGridVM model)
        {
            var returnMessage = this.Bridge.EmployeeUtility.InsertToEmployee(model); 
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
         

            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }

        [HttpPost]
        public JsonResult DeleteEmployee(EmployeeGridVM model)
        {
            //insert items into respective tables
            int id = model.id;
            this.Bridge.EmployeeUtility.Delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public JsonResult UpdateEmployee(EmployeeGridVM model)
        {
            var result = this.Bridge.EmployeeUtility.UpdateEmployee(model);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult GetEmployeesProjects(int id)
        {
            int contactId = this.Bridge.EmployeeUtility.GetcontactIdByEmployeeId(id);
            var scratchPads = this.Bridge.EmployeeUtility.GetEmployeeProjects(contactId);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        protected JsonResult JsonUtc(object data)
        {
            return new DateUTCController.JsonUtcResult
            {
                Data = data
            };
        }

    }
}